import Taro from "@tarojs/taro";
import {useEffect, useState} from "react";
import {Image, View} from "@tarojs/components";
import './index.scss'

export default ()=>{
  const {router} = Taro.getCurrentInstance()
  const [order,setOrder]=useState({
    ticketList:[]
  })

  const goHome=()=>{
    Taro.switchTab({
      url:'/pages/movie/index'
    })
  }

  useEffect(() => {
    Taro.$get('/cinema-app/api/v1/order', {
      orderId: router.params.id
    }).then(res=>{
      if (res.code == '1') {
        res.content.ticketPrice=res.content.ticketList?.reduce((acc, cur) => acc + parseFloat(cur.ticketPrice), 0)
        setOrder(res.content)
      }
    })
  }, []);
  return (
    <View className='page'>
      <View className='page-content'>
        <View className='part-1'>
          <Image className='row-1' src={require('@/images/common/succeed.png')}></Image>
          <View className='row-2'>{order.orderType=='Ticket'?'购票成功':'支付成功'}</View>
          <View className='row-3'>{order.filmNickName}（{order.ticketList.length}张）</View>
          {/*<View className='row-4'>上影 VIP 为您节省 4 元</View>*/}
          <View className='row-5 flex-cc'>
            {/*<View className='col-1 flex-cc' onClick={goHome}>返回首页</View>*/}
            <View className='col-2 flex-cc' onClick={goHome}>返回首页</View>
          </View>
        </View>
        {/*<View className='part-2'>*/}
        {/*  <Image className='img' src={require('@/images/ticket/check_1.png')}></Image>*/}
        {/*</View>*/}
        {/*<View className='part-3'>*/}
        {/*  <Image className='img' src={require('@/images/ticket/check_1.png')}></Image>*/}
        {/*</View>*/}
      </View>
    </View>
  )
}
